using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace DAO
{
    class Dataprovider
    {
        #region le quan dai
        public static OleDbConnection ketnoicsdl()
        {
            string chuoiketnoi = "provider=microsoft.jet.oledb.4.0;data source=qlhocsinh.mdb";
            OleDbConnection con = new OleDbConnection(chuoiketnoi);
            if (con.State == ConnectionState.Closed)
                con.Open();
            return con;
        }
        public static DataTable laythongtinbang(string sql, OleDbConnection con)
        {
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(sql,con);
            da.Fill(dt);
            //con.Close();
            return dt;
            
        }
        
        public static Boolean chaycaulenh(string sql,OleDbConnection con)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(sql, con);
                cmd.ExecuteNonQuery();
                con.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
        
        

#endregion
        #region do thanh hieu
       
        public static DataTable laybang(string sql, OleDbConnection con)
        {
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
            da.Fill(dt);
            con.Close();
            return dt;

        }

        public static bool excecuteNoneQuery(string sQuery, OleDbConnection con)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(sQuery, con);
                cmd.ExecuteNonQuery();
                con.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }



  #endregion

    }
}
